<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>自定义指令</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>

</head>

<body>
    <div id="app">
        <div id="hook-arguments-example" v-demo:foo.a.b="msg"></div>
    </div>

    <script>
        // 全局注册 bg inserted的函数
        Vue.directive('demo', {
            bind: function (el, binding, vnode) {
                // el是当前的dom节点
                console.log(el);
                // 一个对象包含属性
                console.log(binding);
                // Vue 编译生成的虚拟节点。
                console.log(vnode);
                var s = JSON.stringify
                el.innerHTML =
                    'name: ' + s(binding.name) + '<br>' +
                    'value: ' + s(binding.value) + '<br>' +
                    'expression: ' + s(binding.expression) + '<br>' +
                    'argument: ' + s(binding.arg) + '<br>' +
                    'modifiers: ' + s(binding.modifiers) + '<br>' +
                    'vnode keys: ' + Object.keys(vnode).join(', ')
            }
        })

        var app = new Vue({
            el: "#app",
            data: {
                msg: "hello"
            }
        })

    </script>
</body>

</html>